<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({});
    const CommonHead = {
      // 模板视图
      template: `
        <div>
          这是组件
          <button ref="btn" @click="arr.push(arr.length+1)">按钮</button>
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{ item }}  
            </li>  
          </ul>
        </div>
      `,
      data() {
        return {
          msg: '这是组件数据',
          arr: [1,2,3,4]
        }
      },
      beforeCreate(){
        console.log('beforeCreate触发');
        
      },
      created () {
        console.log('created触发');
        
      },
      beforeMount () {
        console.log('beforeMount触发');
        
      },
      mounted () {
        console.log('mounted触发');
        console.log(this.$refs.btn);
      },
      beforeUpdate(){
        console.log('视图更新之前');
        
      },
      updated(){
        console.log('视图更新完成');
        console.log(this.$refs.oul.children);
      }
    }
    app.component('CommonHead', CommonHead)

    app.mount('#app')
  </script>
</body>

</html>